package com.wjw.controller.system;

import com.wjw.entity.User;
import com.wjw.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 127.0.0.1:8081/springboot/user/getUserList
 */
@Controller
@RequestMapping("/user")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @GetMapping("/getUserList")
    @ResponseBody
    public List<User> getUserList(){
        return userService.getUserList();
    }

    @PostMapping("/saveUser")
    @ResponseBody
    public Integer saveUser(User user){
        logger.info("用户名：[{}]",user.getUsername());
        logger.info("密码：[{}]",user.getPassword());
        logger.info("是否删除：[{}]",user.getIfdelete());
        Integer result = 0;
        if(!StringUtils.isEmpty(user)){
            result = userService.saveUser(user);
        }
        return result;
    }
}
